﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Admin_Category : System.Web.UI.Page
{
    protected void LogoutButton_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        FormsAuthentication.SignOut();
        Response.Redirect("~/Default.aspx");
    }
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!Page.IsPostBack)
        {


        }
    }
    protected void CategoryFormView_ItemDeleted(object sender, FormViewDeletedEventArgs e)
    {
        CategoryFormView.DataBind();
    }
    protected void CategoryFormView_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName.ToUpper() == "CANCEL")
            CategoryFormView.ChangeMode(FormViewMode.Insert);
    }
    protected void CategoryGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        CategoryFormView.PageIndex = (CategoryGridView.PageSize * CategoryGridView.PageIndex) + CategoryGridView.SelectedIndex;
        CategoryFormView.ChangeMode(FormViewMode.Edit);
        CategoryGridView.DataBind();
        CategoryGridView.SelectedIndex = -1;
    }
    protected void ClearImageButton_Click(object sender, ImageClickEventArgs e)
    {
        CategoryTitleTextBox.Text = string.Empty;
        CategoryFormView.ChangeMode(FormViewMode.Insert);
        ClearImageButton.OnClientClick = "return false;";
    }
    protected void SearchImageButton_Click(object sender, ImageClickEventArgs e)
    {
        CategoryGridView.PageSize = (PageSizeDropDownList.SelectedIndex == -1 || PageSizeDropDownList.SelectedValue == "0" ? 5 : Convert.ToInt32(PageSizeDropDownList.SelectedValue));
        if (CategoryTitleTextBox.Text != string.Empty)
        {
            CategoryFormView.ChangeMode(FormViewMode.Insert);
            ClearImageButton.OnClientClick = string.Empty;
        }
        else
            ClearImageButton_Click(sender, e);
    }
    protected void NewImageButton_Click(object sender, ImageClickEventArgs e)
    {
        CategoryFormView.ChangeMode(FormViewMode.Insert);
        CategoryFormView.DataBind();
    }
    protected void CategoryEntityDataSource_Command(object sender, EntityDataSourceChangedEventArgs e)
    {
        CategoryGridView.DataBind();
        CategoryFormView.ChangeMode(FormViewMode.Insert);
    }
}